//let COMMON = require("../../Tools/common.js");
let COMMON = require("./common.js");

COMMON.debug = false;
main();

function main() {
  auto.waitFor();
  while (viewTask()) { }
  COMMON.Log('脚本执行结束');
}

function viewTask() {
  if (textMatches(/.*(15[s|秒]).*/).exists()) {
    sleep(500);
    let completeCount = 0;
    let widgets = textMatches(/.*(15[s|秒]).*/).find();
    for (let index = 0; index < widgets.length; index++) {
      let widget = widgets[index];
      let buttonWidget = widget.parent().child(widget.indexInParent() + 1).child(0);
      if (buttonWidget.text() == "去完成" || buttonWidget.text() == "去逛逛") {
        if (buttonWidget.click()) {
          sleep(1000);
          for (let j = 0; j < 4; j++) {
            COMMON.RandomSwipe();
            sleep(5000);
          }
          back();
          sleep(1000);
        }
      }
      else {
        completeCount++;
      }
    }
    return completeCount != widgets.length;
  }
  return false;
}
